package com.ax.base.common.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import com.ax.base.common.domain.SysDict;

@Mapper
public interface SysDictMapper {
    int deleteByPrimaryKey(Long dictId);

    int insert(SysDict record);

    @Insert("insert into sys_dict (Dict_ID, Dict_Code, Dict_Name, "+
		    "First_Letter, Remarks, Parent_Dict_ID, "+
		    "Dict_Type_Code, Dict_Type_Name, Registrar_ID, "+
		    "Registrar_Name, create_date, update_date, "+
		    "Flag)"+
		    "values (#{dictId}, #{dictCode}, #{dictName}," +
		    "#{firstLetter}, #{remarks}, #{parentDictId}, "+
		    "#{dictTypeCode}, #{dictTypeName}, #{registrarId}," +
		    "#{registrarName}, NOW(), #{updateDate}," +
		    "#{flag})")
    int insertSelective(SysDict record);

    SysDict selectByPrimaryKey(Long dictId);

    @Update("<script>"+
    		"update sys_dict"+
    	    "<set >"+
    		"<if test=\"dictCode != null and dictCode != ''\">"+ "Dict_Code = #{dictCode}, " + "</if>" +
    		"<if test=\"dictName != null and dictName != ''\">"+ "Dict_Name = #{dictName}, " + "</if>" +
    		"<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" +
    		"<if test=\"remarks != null and remarks != ''\">"+ "Remarks = #{remarks}, " + "</if>" +
    		"<if test=\"parentDictId != null\">"+ "Parent_Dict_ID = #{parentDictId}, " + "</if>" +
    		"<if test=\"dictTypeCode != null and dictTypeCode != ''\">"+ "Dict_Type_Code = #{dictTypeCode}, " + "</if>" +
    		"<if test=\"dictTypeName != null and dictTypeName != ''\">"+ "Dict_Type_Name = #{dictTypeName}, " + "</if>" +
    		"<if test=\"registrarId != null\">"+ "Registrar_ID = #{registrarId}, " + "</if>" +
    		"<if test=\"registrarName != null and registrarName != ''\">"+ "Registrar_Name = #{registrarName}, " + "</if>" +
    		"<if test=\"createDate != null\">"+ "create_date = #{createDate}, " + "</if>" +
    		"update_date = NOW(), " +
    		"<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
    	    "</set>"+
    	    "where Dict_ID = #{dictId}"+
    	    "</script>")
    int updateByPrimaryKeySelective(SysDict record);

    int updateByPrimaryKey(SysDict record);
    
    /**
	 * 字典查询(模块:字典)
	 * 
	 * @param Map<String,Object> map
	 *           
	 * @return PageUtils
	 */
    @Select("<script>"+
    		"select "+ 
    	    "Dict_ID, Dict_Code, Dict_Name, First_Letter, Remarks, Parent_Dict_ID, Dict_Type_Code,"+ 
    	    "Dict_Type_Name, Registrar_ID, Registrar_Name, create_date, update_date, Flag "+
    	    "from sys_dict"+
    	    "<where>"+ 
         	"<if test=\"dictId != null\">"+ "and Dict_ID = #{dictId} " + "</if>" +
         	"</where>"+
    	   /* "<if test=\"offset != null and limit != null\">"+
    		"limit #{offset}, #{limit}" + 
    		"</if>"+*/
    		"</script>")
    public List<SysDict> querySysDictMapper(Map<String,Object> map);
    
    /**
	 * 分页总计(模块:字典)
	 * 
	 * @param Map<String,Object> map
	 *           
	 * @return Integer
	 */
    @Select("<script>"+
    		"select "+ 
    	    "count(0) "+
    	    "from sys_dict"+
    	    "<where>"+ 
         	"<if test=\"dictId != null\">"+ "and Dict_ID = #{dictId} " + "</if>" +
         	"</where>"+
    		"</script>")
    Integer count(Map<String,Object> map);
    
    /**
	 * 字典详情跳转(修改)
	 * 
	 * @param Long id
	 *           
	 * @return SysDict sysDict
	 */
    @Select("<script>"+
    		"select "+ 
    	    "Dict_ID, Dict_Code, Dict_Name, First_Letter, Remarks, Parent_Dict_ID, Dict_Type_Code,"+ 
    	    "Dict_Type_Name, Registrar_ID, Registrar_Name, create_date, update_date, Flag "+
    	    "from sys_dict"+
    	    "<where>"+ 
         	"<if test=\"dictId != null\">"+ "and Dict_ID = #{dictId} " + "</if>" +
         	"</where>"+
    		"</script>")
    SysDict getQueryMapper(@Param("dictId") Long dictId);
}